// getSeatHours

import axios from "axios";
import dayjs from "dayjs";

/**
 *  $output = [
 *    'start' => $start,
 *    'end' => $end,
 *    'count' => count($result),
 *    'content' => $result,
 *    'users' => $users,
 *    'usersGrouped' => $users_grouped,
 *    // 'sql' => $sql,
 *  ];
 */

export default function (
  start = dayjs().subtract(24, "hour").format("YYYY-MM-DD HH:mm:ss"),
  end = dayjs().format("YYYY-MM-DD HH:mm:ss")
) {
  return new Promise((resolve, reject) => {
    axios
      .request({
        method: "get",
        url: "api/seat_hours_get.php",
        params: { start, end },
      })
      .then((response) => {
        console.log("getSeatHours", `from ${start} to ${end}`, response.data);
        resolve(response.data);
      })
      .catch((error) => {
        console.error("getSeatHours", `from ${start} to ${end}`, error);
        reject(error);
      });
  });
}
